<?php 

class CommonAction extends Action{
	private $Menu;
	public function _initialize(){
		
		if(!isset($_SESSION['user'])){
			$this->redirect("Public/login");
		}
		if(!S('urls')){
			$this->Menu = D('Menu');
			$menus = $this->Menu->getAllMenu();
			foreach($menus as $k=>$v){
				$urls[] = $v['url'];
			}
			$urls = array_unique($urls);
			S('urls',$urls);
			
		}else{
			$urls = S('urls');
		}
		
		// 只验证在系统菜单中存在的菜单，不存在的，不验证
		$url = MODULE_NAME.'/'.ACTION_NAME;
		if(in_array($url, $urls)){ //系统已存在菜单
			$userUrls = $_SESSION['userUrls']; //已授权菜单
			if(!in_array($url, $userUrls)){ // 验证当前菜单是否授权
				$this->error("无权限！");
			}
		}
	}
	
	
}


?>